// SPU管理模块接口
import request from '@/utils/request'
import type { TrademarkResponseData } from './type'

enum API {
  // 查询分类列表接口
  CATEGORY_LIST_URL = '/admin/product/',
  // 获取所有品牌接口
  AllTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  // 获取商品图片
  IMAGE_URL = '/admin/product/spuImageList/',
  // 获取商品销售属性
  SPUSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  // 获取所有的销售属性
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  // 保存SPU接口
  SPU_SAVE_URL = '/admin/product/saveSpuInfo',
  // 编辑SPU接口
  SPU_UPDATE_URL = '/admin/product/updateSpuInfo',
  // 删除属性接口
  SPU_DELETE_URL = '/admin/product/deleteSpu/',
  // 新增SKU接口
  SKU_ADD_URL = '/admin/product/saveSkuInfo',
  // 查询SKU商品
  SKU_QUERY_URL = '/admin/product/findBySpuId/'
}

// 获取列表数据方法
export const reqSpuList = (page: any, limit: any, category3Id: any) => {
  return request.get<any, any>(
    API.CATEGORY_LIST_URL + `${page}/${limit}?category3Id=${category3Id}`
  )
}

// 获取品牌数据方法
export const reqAllTrademarkList = () => {
  return request.get<any, TrademarkResponseData>(API.AllTRADEMARK_URL)
}

// 获取商品图片方法
export const reqSpuImage = (spuId: any) => {
  return request.get<any, any>(API.IMAGE_URL + spuId)
}

// 获取商品销售属性方法
export const reqSpuSaleAttr = (spuId: any) => {
  return request.get<any, any>(API.SPUSALEATTR_URL + spuId)
}

// 获取所有的销售属性方法
export const reqAllSpuSaleAttr = () => {
  return request.get<any, any>(API.ALLSALEATTR_URL)
}

// 保存or编辑方法
export const addOrUpdateSpuReq = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.SPU_UPDATE_URL, data)
  } else {
    return request.post<any, any>(API.SPU_SAVE_URL, data)
  }
}

// 删除品牌方法
export const delSpuReq = (id: any) => {
  return request.delete<any, any>(API.SPU_DELETE_URL + id)
}

// 保存SKU
export const addSkuReq = (data: any) => {
  return request.post<any, any>(API.SKU_ADD_URL, data)
}

// 查询SKU
export const querySkuReq = (id: any) => {
  return request.get<any, any>(API.SKU_QUERY_URL + id)
}
